package cn.zkld.web;

import cn.zkld.Data.FrontResult;
import cn.zkld.model.GoodsInfo;
import cn.zkld.service.SelectGoodsPriceService;
import com.sun.istack.internal.NotNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 按价格排序商品web层
 *
 * Created by 李景辉 on 2017/12/6.
 */
@Controller
public class SelectGoodsPriceController extends Base {
    @Resource
    private SelectGoodsPriceService selectGoodsPriceService;
    /**
     *  查询商品列表按价格排序
     * id 价格排序状态码
     * @param id
     * @return
     */
    @RequestMapping(value="/selectGoodsPrice",method = RequestMethod.GET)
    @ResponseBody
    public FrontResult<List<GoodsInfo>> selectGoodsPrice(@RequestParam("id") int id){
        /* 获取商品种类id作为条件按价格排序*/
        Object parent_id=request.getSession().getAttribute("parent_id");
        Map map=new HashMap();
        map.put("id",id);
        map.put("parent_id",parent_id);
        try{
            List<GoodsInfo> list=selectGoodsPriceService.selectGoodsPrice(map);
           /* map.clear();
            map.put("status",0);
            map.put("message","success");
            map.put("data",list);*/
            return FrontResult.wrapSuccessfulResult(list);
        }catch (Exception e){
            /*map.clear();
            map.put("status",1);
            map.put("message","error");*/
            return FrontResult.wrapFailureResult();
        }
    }
}
